﻿@using ecommerce2011.Common
@using ThisController = ecommerce2011.Controllers.ProductController
@*@model IEnumerable<ecommerce2011.Models.Product>*@
@model GridProductViewModel

@helper Truncate(string input, int length)
    {
     if (input.Length <= length)
     {
        @input
     }
     else
     {
        @input.Substring(0, length)<text>...</text>
     }
}
@{
    ViewBag.Title = "Index";
}

<h2>Resultados de Búsqueda</h2>

<div id="grid">
@{
    <input id="txtCadenaBusqueda" name="txtCadenaBusqueda" type="hidden" value="@Model.CadenaBusqueda"/>
    <input id="selCriterioBusqueda" name="selCriterioBusqueda" type="hidden" value="@Model.CriterioBusqueda" />
    var grid = new WebGrid(canPage: true, rowsPerPage: ThisController.PageSize, canSort: true, ajaxUpdateContainerId: "grid");
    grid.Bind(Model.Productos, rowCount: Model.TotalRecords, autoSortAndPage: false);
    grid.Pager(WebGridPagerModes.All);
    @grid.GetHtml(htmlAttributes: new { id = "grid" },
        columns: grid.Columns(
                    grid.Column(format: (item) => Html.ActionLink("Ver Detalle", "Details", new { id = item.ProductId })),
                    grid.Column("Name", "Nombre"),
                    grid.Column("ArrivalDate", "Fecha de Llegada"),
                    grid.Column("DepartureDate", "Fecha de Salida"),
                    grid.Column("ShowDate", "Fecha del espectácula")
        ));
}
</div>
@*
<table>
    <tr>
        <th>
            Show
        </th>
        <th>
            ShowDate
        </th>
        <th>
            City
        </th>
        <th>
            ArrivalDate
        </th>
        <th>
            DepartureDate
        </th>
@*        <th>
            TransportationRate
        </th>
        <th>
            ShowRate
        </th>
        <th>
            AccommodationRate
        </th>
        <th></th>
    </tr>

@foreach (var item in Model)
{
    <tr>
        <td>
            @Truncate(item.Show, 40)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ShowDate)
        </td>
        <td>
            @Truncate(item.City.Name, 25)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ArrivalDate)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.DepartureDate)
        </td>@*
        <td>
            @Html.DisplayFor(modelItem => item.TransportationRate.NameRate)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ShowRate.NameRate)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.AccommodationRate.NameRate)
        </td>
        <td>
       @*     @Html.ActionLink("Edit", "Edit", new { id = item.ProductId }) |
            @Html.ActionLink("Details", "Details", new { id = item.ProductId }) 
   @*         @Html.ActionLink("Delete", "Delete", new { id = item.ProductId })
        </td>
    </tr>
}

</table>
*@